<%-- 
 *Workshop 
 *Class ID        : SE0691   
 *Student ID      : SE90009
 *Student Name    : Phạm Nguyễn Nhật Trung
 *Due Date        : Nov 23, 2012, 11:24:04 AM
 *I declare that this assignment is my own work
 *in accordance with FPT Policy.
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="Trackertag" uri="/WEB-INF/tlds/TrackerTag_library"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <LINK REL=StyleSheet HREF="../style/style.css" TYPE="text/css" MEDIA=screen>
        <title>Change Password</title>
    </head>
    <body>
        <%
            Boolean isLogin = false;
            int userId = -1;
            try {
                Cookie[] ck = request.getCookies();
                if (ck != null) {
                    for (int i = 0; i < ck.length; i++) {
                        if ("userId".equals(ck[i].getName())) { //Finding Username Cookie
                            userId = Integer.parseInt(ck[i].getValue());
                            i = ck.length;
                            isLogin = true;
                        }
                    }

                }
                if (isLogin == false) {
                    response.sendRedirect("login.jsp");
                    return;
                }
            } catch (Exception e) {
            }
        %>
        <div class="center-form">
            <h1 style="color: whitesmoke">Change Your Password</h1>
            <div id="login-register" style="">
                <form class="tracker-login-form">
                    <p class="clearfix">
                        <label for="login">New Password</label>
                        <input type="text" name="password" id="login" placeholder="Password">
                    </p>
                    <p class="clearfix">
                        <input type="button" name="register" value="Back" onclick="parent.location='listTorrents.jsp'">
                    </p>
                    <p class="clearfix">
                        <input type="submit" name="submit" value="Change">
                    </p>   
                </form>
            </div>
            <%! String password = "";%>
            <%
                try {
                    /* TODO output your page here. You may use following sample code. */
                    if (request.getParameter("password") != null) {
                        try {
                            password = request.getParameter("password");
                        } catch (Exception e) {
                            out.println("<div style=\"width:800px; margin:0 auto; padding-top: 250px\"><h3>" + e.getMessage() + "</h3></div>");
                        }
                    }
                } catch (Exception e) {
                    out.println("<div style=\"width:800px; margin:0 auto; padding-top: 250px\"><h3>" + e.getMessage() + "</h3></div>");
                } finally {
                    //out.close();
                }
            %>
            <Trackertag:chagePasswordTagHandler userId="<%= userId%>" password="<%= password%>" />
        </div>
    </body>
</html>
